import { getInfoDataAll, getInfoDataLike, getInfoDataById , insertInfoDataItem, deleteInfoDataItemByID, getInfoTop5Banner, getInfoTop4 } from '../db/info';
import request from '../util/requset';
import { isOffLine } from '../util/isOffLine';

/**
 * 获取列表全部数据
 * @returns 
 */
export async function getInfoListApi() {
    return isOffLine() ? await getInfoDataAll():await request('/info/queryInfoAll');
}

/**
 * 模糊查询
 * @param {*} params 
 * @returns 
 */
export async function getInfoItemLikeApi(params) {
    return isOffLine() ? await getInfoDataLike(params):await request(`/info/queryLikeInfo?title=${params.title}`);
}

/**
 * 新增
 * @param {*} param 
 * @returns 
 */
export async function addInfoItemApi(param) {
    return  isOffLine() ? await insertInfoDataItem(param):await request('/info/insterInfo',{method:'POST',data:param});
}

/**
 * 根据id获取书签
 * @param {Number} id
 */
export async function queryInfoByIdApi(id) {
    return isOffLine() ? await getInfoDataById(id) : await request('/info/queryInfoById?id='+id);
}


/**
 * 编辑书签
 * @param {*} param
 */
export async function updateInfoApi(param) {
    return isOffLine() ? await insertInfoDataItem(param): await request('/info/updateInfo',{method:'PUT',data:param});
}




/**
 * 删除
 * @param {*} id 
 * @returns 
 */
export async function deleteInfoItemApi(id) {
    return  isOffLine() ? await deleteInfoDataItemByID(id):await request(`/info/delInfoItem?id=${id}`,{method:'DELETE'});
}

/**
 * banner
 * @returns 
 */
export async function getBannerApi() {
    return await getInfoTop5Banner();
}

/**
 * banner
 * @returns 
 */
export async function getTop4Api() {
    return isOffLine() ? await getInfoTop4():await request('/info/queryInfoTop4');
}